package us.mooresr.webtroopmanager.shared;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Id;


import com.google.gwt.user.client.rpc.IsSerializable;


public class User implements IsSerializable {

	@Id private Long userId;
	private String userName;
	private String hashedPassword;
	private String realName;
	private String emailAddress;
	private Boolean enabled;
	private String validationChallenge;
	private Date creationDate;
	private Set<Long> roleIds;
	private Set<Long> personIds;
	
	
	public User() {
		
	}
	
	public User(Long userId, String userName, String hashedPassword, String realName, String emailAddress) {
		super();
		this.userId = userId;
		this.userName = userName;
		this.hashedPassword = hashedPassword;
		this.realName = realName;
		this.emailAddress = emailAddress;
		this.enabled = false;
		this.validationChallenge = "";
		this.creationDate = new Date();
		roleIds = new HashSet<Long>();
		personIds = new HashSet<Long>();
	}
	
	public String toString() {
		return userName;
	}
	
	public Long getUserId() {
		return userId;
	}
	public void setUserId(Long userId) {
		this.userId = userId;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getHashedPassword() {
		return hashedPassword;
	}
	public void setHashedPassword(String hashedPassword) {
		this.hashedPassword = hashedPassword;
	}
	
	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getEmailAddress() {
		return emailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}

	public void clearRoles() {
		roleIds.clear();
	}
	
	public void addRole(Long roleId) {
		if (roleIds == null) {
			roleIds = new HashSet<Long>();
		}
		roleIds.add(roleId);
	}
	
	public Set<Long> getRoleIds() {
		return roleIds;
	}
	
	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}
	
	public Boolean getEnabled() {
		return enabled;
	}

	public String getValidationChallenge() {
		return validationChallenge;
	}

	public void setValidationChallenge(String validationChallenge) {
		this.validationChallenge = validationChallenge;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}
	
	public Set<Long> getPersonIds() {
		return personIds;
	}
	
	public void clearPersonIds() {
		personIds.clear();
	}
	
	public void addPerson(Long personId) {
		if (personIds == null) {
			personIds = new HashSet<Long>();
		}
		personIds.add(personId);
	}
	

}
